package com.mxsat.common.dao;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mxsat.common.entity.Entity;

public interface Dao<T extends Entity> {
	 /**
     * <p>
     * 鎻掑叆涓�鏉¤褰曪紙閫夋嫨瀛楁锛岀瓥鐣ユ彃鍏ワ級
     * </p>
     *
     * @param entity 瀹炰綋瀵硅薄
     */
    boolean save(T entity);

    /**
     * <p>
     * 鎻掑叆锛堟壒閲忥級锛岃鏂规硶涓嶉�傚悎 Oracle
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     */
    default boolean saveBatch(Collection<T> entityList) {
        return saveBatch(entityList, 30);
    }

    /**
     * <p>
     * 鎻掑叆锛堟壒閲忥級
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     * @param batchSize  鎻掑叆鎵规鏁伴噺
     */
    boolean saveBatch(Collection<T> entityList, int batchSize);

    /**
     * <p>
     * 鎵归噺淇敼鎻掑叆
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     */
    boolean saveOrUpdateBatch(Collection<T> entityList);

    /**
     * <p>
     * 鎵归噺淇敼鎻掑叆
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     * @param batchSize  姣忔鐨勬暟閲�
     */
    boolean saveOrUpdateBatch(Collection<T> entityList, int batchSize);

    /**
     * <p>
     * 鏍规嵁 ID 鍒犻櫎
     * </p>
     *
     * @param id 涓婚敭ID
     */
    boolean removeById(Serializable id);

    /**
     * <p>
     * 鏍规嵁 columnMap 鏉′欢锛屽垹闄よ褰�
     * </p>
     *
     * @param columnMap 琛ㄥ瓧娈� map 瀵硅薄
     */
    boolean removeByMap(Map<String, Object> columnMap);

    /**
     * <p>
     * 鏍规嵁 entity 鏉′欢锛屽垹闄よ褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋鍖呰绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    boolean remove(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鍒犻櫎锛堟牴鎹甀D 鎵归噺鍒犻櫎锛�
     * </p>
     *
     * @param idList 涓婚敭ID鍒楄〃
     */
    boolean removeByIds(Collection<? extends Serializable> idList);

    /**
     * <p>
     * 鏍规嵁 ID 閫夋嫨淇敼
     * </p>
     *
     * @param entity 瀹炰綋瀵硅薄
     */
    boolean updateById(T entity);

    /**
     * <p>
     * 鏍规嵁 whereEntity 鏉′欢锛屾洿鏂拌褰�
     * </p>
     *
     * @param entity        瀹炰綋瀵硅薄
     * @param updateWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper}
     */
    boolean update(T entity, Wrapper<T> updateWrapper);

    /**
     * <p>
     * 鏍规嵁ID 鎵归噺鏇存柊
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     */
    default boolean updateBatchById(Collection<T> entityList) {
        return updateBatchById(entityList, 30);
    }

    /**
     * <p>
     * 鏍规嵁ID 鎵归噺鏇存柊
     * </p>
     *
     * @param entityList 瀹炰綋瀵硅薄闆嗗悎
     * @param batchSize  鏇存柊鎵规鏁伴噺
     */
    boolean updateBatchById(Collection<T> entityList, int batchSize);

    /**
     * <p>
     * TableId 娉ㄨВ瀛樺湪鏇存柊璁板綍锛屽惁鎻掑叆涓�鏉¤褰�
     * </p>
     *
     * @param entity 瀹炰綋瀵硅薄
     */
    boolean saveOrUpdate(T entity);

    /**
     * <p>
     * 鏍规嵁 ID 鏌ヨ
     * </p>
     *
     * @param id 涓婚敭ID
     */
    T getById(Serializable id);

    /**
     * <p>
     * 鏌ヨ锛堟牴鎹甀D 鎵归噺鏌ヨ锛�
     * </p>
     *
     * @param idList 涓婚敭ID鍒楄〃
     */
    Collection<T> listByIds(Collection<? extends Serializable> idList);

    /**
     * <p>
     * 鏌ヨ锛堟牴鎹� columnMap 鏉′欢锛�
     * </p>
     *
     * @param columnMap 琛ㄥ瓧娈� map 瀵硅薄
     */
    Collection<T> listByMap(Map<String, Object> columnMap);

    /**
     * <p>
     * 鏍规嵁 Wrapper锛屾煡璇竴鏉¤褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    default T getOne(Wrapper<T> queryWrapper) {
        return getOne(queryWrapper, false);
    }

    /**
     * <p>
     * 鏍规嵁 Wrapper锛屾煡璇竴鏉¤褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     * @param throwEx      鏈夊涓� result 鏄惁鎶涘嚭寮傚父
     */
    T getOne(Wrapper<T> queryWrapper, boolean throwEx);

    /**
     * <p>
     * 鏍规嵁 Wrapper锛屾煡璇竴鏉¤褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    Map<String, Object> getMap(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鏍规嵁 Wrapper锛屾煡璇竴鏉¤褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    Object getObj(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鏍规嵁 Wrapper 鏉′欢锛屾煡璇㈡�昏褰曟暟
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    int count(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鏌ヨ鍒楄〃
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    List<T> list(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 缈婚〉鏌ヨ
     * </p>
     *
     * @param page         缈婚〉瀵硅薄
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    IPage<T> page(IPage<T> page, Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鏌ヨ鍒楄〃
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    List<Map<String, Object>> listMaps(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 鏍规嵁 Wrapper 鏉′欢锛屾煡璇㈠叏閮ㄨ褰�
     * </p>
     *
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    List<Object> listObjs(Wrapper<T> queryWrapper);

    /**
     * <p>
     * 缈婚〉鏌ヨ
     * </p>
     *
     * @param page         缈婚〉瀵硅薄
     * @param queryWrapper 瀹炰綋瀵硅薄灏佽鎿嶄綔绫� {@link com.baomidou.mybatisplus.core.conditions.query.QueryWrapper}
     */
    IPage<Map<String, Object>> pageMaps(IPage<T> page, Wrapper<T> queryWrapper);
}